package io.bba.boot.app.controller;

import io.bba.boot.framework.page.Paging;
import io.bba.boot.framework.response.ApiResult;
import io.bba.boot.app.query.AppArticleQuery;
import io.bba.boot.app.service.ArticleService;
import io.bba.boot.app.vo.AppArticleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * App文章 控制器
 *
 * @author zs
 * @since 2024-03-22
 */
@Slf4j
@RestController
@Tag(name = "App文章")
@RequestMapping("/app/article")
public class AppArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 获取App文章详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App文章详情")
    @PostMapping("/getAppArticle/{id}")
    public ApiResult<AppArticleVo> getAppArticle(@PathVariable Long id) {
        log.info("获取App文章详情：{}", id);
        AppArticleVo appArticleVo = articleService.getAppArticleById(id);
        return ApiResult.success(appArticleVo);
    }

    /**
     * 获取App文章分页列表
     *
     * query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App文章分页列表")
    @PostMapping("/getAppArticlePage")
    public ApiResult<AppArticleVo> getAppArticlePage(@Valid @RequestBody AppArticleQuery query) {
        log.info("获取App文章分页列表：{}", query);
        Paging<AppArticleVo> paging = articleService.getAppArticlePage(query);
        return ApiResult.success(paging);
    }

}
